package Entity

class ClassEntity {

    private var name:String = ""
    private var fields:ArrayList<FieldEntity>  = ArrayList()
    private var methods:ArrayList<MethodEntity>  = ArrayList()

    constructor(name: String) {
        this.name = name
    }


    /**
     * 添加一个成员变量
     */
    fun addField(fieldEntity: FieldEntity) = this.fields.add(fieldEntity)

    /**
     * 添加一个方法
     */
    fun addMethod(methodEntity: MethodEntity) = this.methods.add(methodEntity)


    override fun toString():String {
        val sb:StringBuilder = StringBuilder();
        sb.append("class $name {\n")
        for (i in 0 until fields.size) {
            sb.append("\t").append(fields[i].toString()).append("\n")
        }
        for (i in 0 until methods.size) {
            sb.append("\t").append(methods[i].toString()).append("\n")
        }
        sb.append("}")
        sb.append("\n")
        return sb.toString();
    }
}